Skip to content

Add not_int intrinsic for for-loop iteration support#107

Merged
maleadt merged 2 commits intoJuliaGPU:mainfrom
0xtaruhi:fix/not-int-for-loops
Mar 17, 2026
Merged

Add not_int intrinsic for for-loop iteration support#107
maleadt merged 2 commits intoJuliaGPU:mainfrom
0xtaruhi:fix/not-int-for-loops

Conversation

@0xtaruhi
Copy link
Contributor

@0xtaruhi 0xtaruhi commented Mar 6, 2026

Summary

Julia desugars for i in 1:n into Core.Intrinsics.not_int to negate the loop-exit condition. Without handling this intrinsic, any kernel using for loops hits IRError("Unhandled Julia intrinsic: not_int").

Implementation: not_int(x)xori(x, allones) where:

  • Bool → xori(x, true) (logical negation)
  • Integer → xori(x, -1) (bitwise complement, all bits set)

Changes

File Change
src/compiler/intrinsics/julia.jl not_int dispatch + emit_not_int!
test/codegen/operations.jl ~ (bitwise NOT) codegen test
test/execution/basic.jl ~ execution test + 3 for-loop execution tests

Tests

  • map(~, tile) bitwise NOT correctness
  • for i in Int32(1):n_iters — literal bound
  • for i in Int32(1):Int32(n_iters)ct.Constant bound
  • for j in Int32(1):len — dynamic bound from scalar indexing

Depends on

- Handle Core.Intrinsics.not_int via xori(x, allones) in julia.jl
- Enables Julia's standard `for i in 1:n` loops in kernels
- Add bitwise NOT (~) codegen test
- Add execution tests: for-loop with literal, constant, and dynamic bounds
@maleadt maleadt force-pushed the fix/not-int-for-loops branch from 6e038ef to d7a8c24 Compare March 17, 2026 14:34
@maleadt maleadt added the enhancement New feature or request label Mar 17, 2026
@maleadt
Copy link
Member

maleadt commented Mar 17, 2026

Test failures are tricky, and related to IR structurizing. Let's reduce the scope to just not_int for now.

@maleadt maleadt merged commit a690744 into JuliaGPU:main Mar 17, 2026
9 checks passed
@maleadt
Copy link
Member

maleadt commented Mar 17, 2026

I've copied the failing tests into maleadt/IRStructurizer.jl#1 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants